package com.hadoop.mr.writable;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.lib.db.DBWritable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by Administrator on 2019/7/11.
 */
public class ClientWritable implements Writable, DBWritable {

    private String nameClient;
    private String goodsName;
    private String goodsType;
    private String client;
    private Integer count;


    public ClientWritable() {
    }

    public String getNameClient() {
        return nameClient;
    }

    public void setNameClient(String nameClient) {
        this.nameClient = nameClient;
    }

    public Integer getCount() {
        return count;
    }

    public void setCount(Integer count) {
        this.count = count;
    }

    public String getGoodsName() {
        return goodsName;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }

    public String getGoodsType() {
        return goodsType;
    }

    public void setGoodsType(String goodsType) {
        this.goodsType = goodsType;
    }

    public String getClient() {
        return client;
    }

    public void setClient(String client) {
        this.client = client;
    }

    public ClientWritable(String nameClient, String goodsName, String goodsType, String client, Integer count) {
        this.nameClient = nameClient;
        this.goodsName = goodsName;
        this.goodsType = goodsType;
        this.client = client;
        this.count = count;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(goodsName);
        out.writeUTF(goodsType);
        out.writeUTF(client);
        out.writeInt(count);
    }


    @Override
    public void readFields(DataInput in) throws IOException {
        goodsName = in.readUTF();
        goodsType = in.readUTF();
        client = in.readUTF();
        count= in.readInt();
    }

    @Override
    public void write(PreparedStatement preparedStatement) throws SQLException {
        preparedStatement.setString(1, this.goodsName);
        preparedStatement.setString(2, this.goodsType);
        preparedStatement.setString(3, this.client);
        preparedStatement.setInt(4, this.count);
    }

    @Override
    public void readFields(ResultSet resultSet) throws SQLException {
        this.goodsName = resultSet.getString(1);
        this.goodsType = resultSet.getString(2);
        this.client = resultSet.getString(3);
        this.count = resultSet.getInt(4);
    }


}

